home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ivbsrc / prtinfo1.frm < prev    next >
Text File  |  1995-05-08  |  5KB  |  140 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Get default printer info"
  4.    ClientHeight    =   4515
  5.    ClientLeft      =   3540
  6.    ClientTop       =   1425
  7.    ClientWidth     =   3645
  8.    FontBold        =   -1  'True
  9.    FontItalic      =   0   'False
  10.    FontName        =   "MS Sans Serif"
  11.    FontSize        =   12
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   4920
  15.    Left            =   3480
  16.    LinkMode        =   1  'Source
  17.    LinkTopic       =   "Form1"
  18.    ScaleHeight     =   4515
  19.    ScaleWidth      =   3645
  20.    Top             =   1080
  21.    Width           =   3765
  22.    WindowState     =   1  'Minimized
  23.    Begin CommandButton Command2 
  24.       Caption         =   "End"
  25.       Height          =   255
  26.       Left            =   2400
  27.       TabIndex        =   3
  28.       Top             =   3240
  29.       Width           =   615
  30.    End
  31.    Begin CommandButton Command1 
  32.       Caption         =   "Get Default Printer Info"
  33.       Height          =   255
  34.       Left            =   120
  35.       TabIndex        =   0
  36.       Top             =   3240
  37.       Width           =   2295
  38.    End
  39.    Begin Label lblLPI 
  40.       BorderStyle     =   1  'Fixed Single
  41.       Caption         =   "Label1"
  42.       Height          =   255
  43.       Left            =   120
  44.       TabIndex        =   5
  45.       Top             =   1920
  46.       Width           =   3375
  47.    End
  48.    Begin Label lblPort 
  49.       Height          =   255
  50.       Left            =   240
  51.       TabIndex        =   2
  52.       Top             =   960
  53.       Width           =   3135
  54.    End
  55.    Begin Label lblDriver 
  56.       Height          =   255
  57.       Left            =   240
  58.       TabIndex        =   1
  59.       Top             =   600
  60.       Width           =   3135
  61.    End
  62.    Begin Label lblPrinter 
  63.       Height          =   255
  64.       Left            =   240
  65.       TabIndex        =   4
  66.       Top             =   240
  67.       Width           =   3135
  68.    End
  69. End
  70. Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer
  71. Dim PageScale As POINTAPI, PageSize As POINTAPI
  72.  
  73. Sub Command1_Click ()
  74.   lpAppName$ = "windows"
  75.   lpKeyName$ = "device"
  76.   nSize% = 81
  77.   lpRetStr$ = Space$(nSize%)
  78.   NumChars% = GetProfileString(lpAppName$, lpKeyName$, NullStr$, lpRetStr$, nSize%)
  79.   koRetStr$ = Left$(lpRetStr$, NumChars%)
  80.   CommaPos1% = InStr(1, lpRetStr$, ",")
  81.   CommaPos2% = InStr(CommaPos1% + 1, lpRetStr$, ",")
  82.   lblPrinter.Caption = "Printer: " + Left$(lpRetStr$, CommaPos1% - 1)
  83.   lblDriver.Caption = "Driver: " + Mid$(lpRetStr$, CommaPos1% + 1, CommaPos2% - CommaPos1% - 1) + ".DRV"
  84.   lblPort.Caption = "Port: " + Mid$(lpRetStr$, CommaPos2% + 1)
  85.   
  86.     Result% = Escape(Printer.hDC, GETPHYSPAGESIZE, NULL, NULL, PageSize)
  87.     Orientation% = Escape(Printer.hDC, GETSETPRINTORIENT, 0, NULL, NULL)
  88.     Result% = DeviceInfo%()
  89.     Select Case Orientation%
  90.       Case 1
  91.     '    lblOrientation.Caption = "Orientation: Portrait"
  92.         X_Size! = PageSize.X / PageScale.X
  93.         Y_Size! = PageSize.Y / PageScale.Y
  94.         Vertical_resolution = PageScale.Y
  95.       Case 2
  96.     '    lblOrientation.Caption = "Orientation: Landscape"
  97.         Y_Size! = PageSize.X / PageScale.X
  98.         X_Size! = PageSize.Y / PageScale.Y
  99.         Vertical_resolution = PageScale.X
  100.       Case Else
  101.     '    lblOrientation.Caption = ""
  102.     End Select
  103.     If X_Size > 0 And Y_Size > 0 Then
  104.       Page_Size$ = Str$(X_Size!) + " x" + Str$(Y_Size!)
  105.     '  lblPaperSize.Caption = "Page Size:" + Page_Size$ + " inches"
  106.     Else
  107.     '  lblPaperSize.Caption = ""
  108.     End If
  109.     'lblXSize.Caption = "X Size = " + Str$(X_Size!)
  110.     'lblYSize.Caption = "Y Size = " + Str$(Y_Size!)
  111.     'lblVerticalResolution.Caption = "Vertical Resolution = " + Str$(Vertical_resolution)
  112.     Result% = DeviceInfo%()
  113.     'lblScaleX.Caption = "Pixels X: " + Str$(PageScale.X)
  114.     'lblScaleY.Caption = "Pixels Y: " + Str$(PageScale.Y)
  115.     LPI% = Lines_Per_Inch(Int(PageScale.Y))
  116.   lblLPI.Caption = Str$(LPI%)
  117. End Sub
  118.  
  119. Sub Command2_Click ()
  120.   End
  121. End Sub
  122.  
  123. Function DeviceInfo () As Integer
  124.   On Error GoTo Device_Error
  125.   DeviceInfo = True
  126.   PageScale.X = GetDeviceCaps(Printer.hDC, LOGPIXELSX)
  127.   PageScale.Y = GetDeviceCaps(Printer.hDC, LOGPIXELSY)
  128.   Exit Function
  129. Device_Error:
  130.   DeviceInfo = False
  131.   Exit Function
  132. End Function
  133.  
  134. Function Lines_Per_Inch (Pixels_Per_Inch As Integer) As Single
  135.   Dim TextMetrix As TEXTMETRIC
  136.   Result% = GetTextMetrics(Printer.hDC, TextMetrix)
  137.   Lines_Per_Inch = Pixels_Per_Inch / (TextMetrix.tmHeight + TextMetrix.tmExternalLeading)
  138. End Function
  139.  
  140.